package senpec.qc.harmony.person.certification;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import senpec.qc.harmony.base.exception.NoResultException;
import senpec.qc.harmony.base.mybatisplus.IBaseServiceImpl;
import senpec.qc.harmony.base.mybatisplus.Result;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
public class CertificationServiceImpl extends IBaseServiceImpl<CertificationMapper, Certification> implements CertificationService {
    private final CertificationMapper certificationMapper;

    @Override
    public Result<Certification> getById(Long id) {
        Certification certification = certificationMapper.selectById(id);
        if (certification == null) {
            throw new NoResultException("未找到该数据");
        } else {
            return Result.ok(certification);
        }
    }

    @Override
    public Result<List<Certification>> getListByConditions(Certification conditions) {
        List<Certification> certifications = certificationMapper.selectList(null);
        return Result.ok(certifications);
    }

    @Override
    public Result<Certification> insertOne(Certification entity) {
        certificationMapper.insert(entity);
        return Result.ok(entity);
    }

}